import asyncio
from functools import wraps
import json


def stream_wrapper(func):
    @wraps(func)
    async def wrapper(*args, **kwargs):
        async for event in func(*args, **kwargs):
            yield json.dumps(event, ensure_ascii=False) + '\n'
            await asyncio.sleep(0)
    return wrapper